// i.d(t, { k: () => BoxVolume })
import * as THREE from "three"
import PureObservable from "../observer/pure.observer"

export default class BoxVolume extends PureObservable {
  box: THREE.Box3
  center: THREE.Vector3
  size: THREE.Vector3
  orientation: THREE.Quaternion
  inverseOrientation: THREE.Quaternion
  pointCache: THREE.Vector3
  transformNeedsUpdate: boolean
  constructor() {
    super()
    this.box = new THREE.Box3()
    this.center = new THREE.Vector3()
    this.size = new THREE.Vector3(1 / 0, 1 / 0, 1 / 0)
    this.orientation = new THREE.Quaternion()
    this.inverseOrientation = new THREE.Quaternion()
    this.pointCache = new THREE.Vector3()
    this.transformNeedsUpdate = !1
    this.box.setFromCenterAndSize(this.center, this.size)
  }
  get origin() {
    return this.center
  }
  updateCenter(e) {
    this.center.copy(e)
    this.box.setFromCenterAndSize(this.center, this.size)
    this.transformNeedsUpdate = !0
  }
  updateDimensions(e) {
    this.size.copy(e)
    this.box.setFromCenterAndSize(this.center, this.size)
  }
  updateOrientation(e) {
    this.orientation.copy(e)
    this.transformNeedsUpdate = !0
  }
  containsPoint(e) {
    this.transformNeedsUpdate && ((this.transformNeedsUpdate = !1), this.inverseOrientation.copy(this.orientation).invert())
    this.pointCache.copy(e).sub(this.center)
    this.pointCache.applyQuaternion(this.orientation)
    this.pointCache.add(this.center)
    return this.box.containsPoint(this.pointCache)
  }
}
